<?php

namespace addon\lian\model\sqlmodel;

use addon\lian\model\sqlmodel\GoodsModel;
use addon\lian\model\sqlmodel\GoodsSkuModel;
use think\Model;


class LianGoodsModel extends Model
{
    protected $name = 'lian_goods';


    protected $pk = 'id';

    protected $json = ['reward_set'];

    protected $jsonAssoc = true;


    public function goods()
    {
        return $this->hasOne(GoodsModel::class, 'goods_id', 'goods_id');
    }


    /**
     * 关联默认商品规格
     * @return \think\model\relation\HasOne
     */
    public function goodsSku()
    {
        return $this->hasOne(GoodsSkuModel::class, 'goods_id', 'goods_id');
    }


    public function getLianGoodsIdList(){
        $list = self::where('site_id', $this->site_id)
            ->where('is_lian', '=', 1)
            ->pluck('goods_id')
            ->select()
            ->toArray();

        return $list;
    }

     /**
     * 关联商品规格列表
     * @return \think\model\relation\HasMany
     */
    public function skuList()
    {
        return $this->hasMany(GoodsSkuModel::class, 'goods_id', 'goods_id');
    }
}